var g, _extends = Object.assign || function (t) {
    for (var e = 1; e < arguments.length; e++) {
      var a, r = arguments[e];
      for (a in r) Object.prototype.hasOwnProperty.call(r, a) && (t[a] = r[a]);
    }
    return t;
  },
  _tools = require("../../utils/tools"),
  app = getApp(),
  page = app.page,
  request = app.util.request,
  route = app.route,
  toast = app.toast;
page({
  data: {
    jin_score: "",
    yin_score: "",
    tong_score: "",
    fei_score: "",
    useInfo: "",
    score_goods: [],
    typeList: [{
        name: "全部",
        value: ''
      },
      {
        name: "铜钻",
        value: 3
      },
      {
        name: "银钻",
        value: 2
      },
      {
        name: "金钻",
        value: 1
      },
      {
        name: "翡翠",
        value: 4
      }
    ],
    currentType: 0,
    no_data: app.srcRoot + "no_data.png",
    isShow: false,
    goods: {},
    popupType: 1,
    mobile: '',
    toUser: {}
  },
  onLoad: function (t) {
    g = this;
    let userInfo = wx.getStorageSync("userInfo")
    if (userInfo) {
      request({
        url: "AddUsersLog",
        data: {
          user_id: userInfo.id,
          url: '/fenxiao/goods/goods',
          title: "积分商城"
        },
        success: function (a) {}
      })
      request({
        url: "Openid",
        showLoading: !1,
        data: {
          user_id: g.data.userInfo.id
        },
        success: function (t) {
          wx.setStorageSync("userInfo", t)
          g.setData({
            userInfo: t
          })
        }
      })
    }
    g.getInfo()
  },
  onReady: function () {
    var t = wx.getSystemInfoSync().screenWidth,
      e = .04 * t,
      t = (e * e + t * t / 4) / (2 * e);
    g.setData({
      style: "background: radial-gradient(circle at 50% " + (e - t) + "px, " + wx.getStorageSync("system").foot_color2 + " " + t + "px, rgba(0,0,0,0) " + t / 2 + "px);"
    }), (0, _tools.getNodeInfo)({
      id: "#top",
      success: function (t) {
        // return g.setData({
        //   top: t.bottom
        // });
      }
    });
  },
  onShow: function () {

  },
  onPullDownRefresh: function () {

  },
  toPage: function(t) {
    var url = t.currentTarget.dataset.url;
    wx.navigateTo({
      url
    })
  },
  goAgreement(){
    request({
      url: "ScoreContent",
      showLoading: !1,
      data: {},
      success: function(t) {
        app.centent = t.content
        wx.navigateTo({
          url: '/u_pages/html_page/index?title=积分攻略',
        })
      }
    })
  },
  mobileInput: function (e) {
    g.setData({
      mobile: e.detail.value
    })
  },
  exchangeScore: function () {
    request({
      url: "ExchangeScore",
      showLoading: !1,
      data: {
        user_id: g.data.userInfo.id,
        mobile: g.data.mobile,
        goods_id: g.data.goods.id
      },
      success: function (t) {
        toast("兑换成功");
        g.setData({
          mobile: '',
          toUser: {},
          isShow: false
        })
        g.getInfo()
      }
    })
  },
  getUser: function (t) {
    if(!g.data.mobile){
      toast("请填写需要兑换此服务手机号")
      return false
    }
    request({
      url: "IssetMobile",
      showLoading: !1,
      data: {
        user_id: g.data.userInfo.id,
        mobile: g.data.mobile
      },
      success: function (t) {
        g.setData({
          toUser: t,
          popupType: 2,
          isShow: true
        })
      },
      fail: function () {
        wx.hideToast()
        g.setData({
          popupType: 3,
          isShow: true
        })
      }
    })
  },
  isShow: function (t) {
    g.setData({
      isShow: false
    })
  },
  onGoods: function (t) {
    var index = t.currentTarget.dataset.index;
    g.setData({
      goods: g.data.score_goods[index],
      isShow: true,
      popupType: 1
    })
  },
  getInfo: function () {
    request({
      url: "ScoreGoodsList",
      showLoading: !1,
      data: {
        user_id: g.data.userInfo.id,
        score_type: g.data.typeList[g.data.currentType].value
      },
      success: function (t) {
        g.setData({
          ...t
        })
      }
    })
  },
  navChange: function (t) {
    var index = t.currentTarget.dataset.index;
    g.setData({
      currentType: index
    })
    g.getInfo()
  }
});